package com.unitd.frame.comm.serializer;

import com.unitd.frame.comm.serializer.impl.KryoPoolSerializer;

import java.io.IOException;

/**
 * @desc 对象序列化工具
 * @filename Serializer.java
 * @copyright www.unitd.com
 * @author Hudan
 * @version 1.0
 * @date 2016/11/28
 */
public class SerializeUtils {

	private static KryoPoolSerializer serializer = new KryoPoolSerializer();

	/**
	 * @desc 序列化指定的对象
	 * @param object 需要序列化的对象
	 * @return
	 */
	public static byte[] serialize(Object object) {
		try {
			return serializer.serialize(object);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	/**
	 * @desc 反序列化指定的已序列化对象
	 * @param bytes 需要被反序列化的数据
	 * @return
	 */
	public static Object deserialize(byte[] bytes) {
		try {
			return serializer.deserialize(bytes);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
}